package pkgscanner.filter;

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Set;

/**
 * @author 星环
 * @date 2023/3/9 16:36:08
 * @description
 */
public class AnnotationScanFilter implements ScanFilter{
    //将支持的注解加入这个
    private FilterMode mode = FilterMode.EXCLUSIVE;
    Set<Class<? extends Annotation>> inclusiveAnnotationList;
    Set<Class<? extends Annotation>> exclusiveAnnotationList;

    public FilterMode getMode() {
        return mode;
    }

    public void setMode(FilterMode mode) {
        this.mode = mode;
    }

    /**
     * add all annotations into inclusiveList
     * @param classes annotations not to be filtered
     */
    public void addInclusiveAnnotation(List<Class<? extends Annotation>> classes){
        inclusiveAnnotationList.addAll(classes);
    }

    public void addExclusiveAnnotation(List<Class<? extends Annotation>> classes){
        exclusiveAnnotationList.addAll(classes);
    }

    @Override
    public boolean filter(Class<?> tClass) {
        return switch (mode){
            case INCLUSIVE -> inclusiveAnnotationList.contains(tClass);
            case EXCLUSIVE -> !exclusiveAnnotationList.contains(tClass);
        };
    }
}
